﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Elasticsearch.Net;
using Nest;

namespace Web
{
    public class NestHelper
    {
        public static ElasticClient GetElasticClient(string indexName)
        {
            var connectString = "http://127.0.0.1:9200";
            var nodesStr = connectString.Split('|');
            var nodes = nodesStr.Select(s => new Uri(s)).ToList();
            var connectionPool = new SniffingConnectionPool(nodes);
            var settings = new ConnectionSettings(connectionPool);
            if (!string.IsNullOrWhiteSpace(indexName))
            {
                settings.DefaultIndex(indexName);
            }
            var client = new ElasticClient(settings);
            return client;
        }

        /// <summary>
        /// 创建索引
        /// </summary>
        /// <param name="indexName"></param>
        private static void CreateIndex(string indexName)
        {
            //var client = ElasticsearchHelper.GetElasticClient("");
            ////client 不能给 default
            //client.CreateIndex(r => r.Index(indexName).NumberOfReplicas(1).NumberOfShards(20));
            //client.Map<Order>(m => m.MapFromAttributes());
        }
    }
}